package com.flyme.module.base.provider.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.flyme.common.core.model.ResultBody;
import com.flyme.common.core.model.query.CriteriaQuery;
import com.flyme.common.core.model.query.PagerInfo;
import com.flyme.common.core.model.query.PqGrid;
import com.flyme.core.base.supper.controller.BaseController;
import com.flyme.core.base.supper.entity.EntityMap;
import com.flyme.module.base.client.api.SysVersionsRemoteService;
import com.flyme.module.base.client.entity.*;
import com.flyme.module.base.provider.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;


/**
 * 企业端-员工管理
 *
 * @author zyf
 */
@Api(tags = "版本管理")
@RestController
public class SysVersionsController extends BaseController<SysVersionService, SysVersion> implements SysVersionsRemoteService {

    /**
     * 版本列表
     */
    @ApiOperation(value = "版本列表", notes = "版本列表")
    public ResultBody list(@ModelAttribute PagerInfo pagerInfo) {
        CriteriaQuery cq = new CriteriaQuery<EntityMap>(pagerInfo);
        cq.select("*");
        PqGrid pqGrid = bizService.pageList(cq);
        return ResultBody.success(pqGrid);
    }

    /**
     * 更新版本
     */
    @ApiOperation(value = "更新版本", notes = "更新版本")
    public ResultBody updateVersion(@ModelAttribute SysVersion version) {
        Boolean tag = bizService.saveOrUpdate(version);
        return ResultBody.success("更新成功").setData(tag);
    }

    /**
     * 更新强制更新
     */
    @ApiOperation(value = "设置强制更新", notes = "设置强制更新")
    public ResultBody setForceUpdate(@RequestParam Long id, @RequestParam Integer forceUpdate) {
        boolean result = bizService.update(new UpdateWrapper<SysVersion>().set("forceUpdate", forceUpdate).eq("id", id));
        return ResultBody.ok("设置成功").setData(result);
    }

    /**
     * 获取版本详情
     */
    @ApiOperation(value = "获取版本详情", notes = "获取版本更新")
    public ResultBody getVersion(@PathVariable Long id) {
        SysVersion version = bizService.getById(id);
        System.out.println("sssss");
        return ResultBody.success(version);
    }

}
